<!--
 * @Author: byron
 * @Date: 2021-09-01 09:01:13
 * @LastEditTime: 2021-09-01 20:07:12
-->

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- 准备容器 -->
    <div id="test"></div>

    <!-- 引入必要的js库 -->
    <script type="text/javascript" src="../../lib/react.development.js"></script>
    <script type="text/javascript" src="../../lib/react-dom.development.js"></script>
    <!-- 引入babel库进行语法转化 -->
    <script type="text/javascript" src="../../lib/babel.min.js"></script>


    <script type="text/babel">
        class Login extends React.Component{
            handleSubmit = (e) => {
                console.log(e);
                e.preventDefault() //阻止表单提交
                console.log('登录');
                const {username,password} = this
                alert(`用户名${username.value}密码${password.value}`)
            }
            render(){
                return (
                    <form action="" onSubmit={this.handleSubmit}>
                    用户名：<input ref={c => this.username = c} type="text" name="username"/>    
                    密码：<input ref={c => this.password = c} type="password" name="password" />
                    <button>登录</button>    
                    </form>
                )
            }
        }
        ReactDOM.render(<Login />,document.querySelector('#test'))
    </script>
</body>

</html>